﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Services;
using CoyoEden.Web.Controls;
using CoyoEden.Web.Data;
using System.Web.Services;
using CoyoEden.Web.Controller;
using Vivasky.Core.Infrastructure;

namespace CoyoEden.Web.Services
{
	[ScriptService]
	public class Topic : WebService
	{
		#region member variables
		private ViewManager<TopicViewBase> vm = null;
		#endregion

		#region methods
		[WebMethod]
		public FeedbackData PreEdit(Dictionary<string, string> Params)
		{

			FeedbackData retVal = new FeedbackData();
			Models.Topic tempObj = TopicController.Single(Params, out retVal);
			if (tempObj != null)
			{
				retVal.Context.Add("data",tempObj);
			}
			return retVal;
		}
		[WebMethod]
		public FeedbackData Update(List<NameValuePair<string, string>> Params)
		{
			FeedbackData retVal = new FeedbackData();
			var tempObj=TopicController.Update(Params, out retVal);
			if(retVal.IsOk==false)
				return retVal;

			vm = new ViewManager<TopicViewBase>("~/Views/TopicView.ascx");
			vm.Control.TheTopic = tempObj;
			retVal.Body = vm.Render();
			return retVal;
		}
		[WebMethod]
		public FeedbackData Delete(Dictionary<string, string> Params)
		{
			FeedbackData retVal = new FeedbackData();
			TopicController.Delete(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData SelectTopics(Dictionary<string, string> Params)
		{
			FeedbackData retVal = null;
			TopicController.SelectTopics(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData ApproveTopic(Dictionary<string, string> Params) {
			FeedbackData retVal = null;
			TopicController.ApproveTopic(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData UpdateTags(Dictionary<string, string> Params)
		{
			FeedbackData retVal = null;
			TopicController.UpdateTags(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData AddComment(List<NameValuePair<string, string>> Params)
		{
			FeedbackData retVal = null;
			TopicController.AddComment(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData RemoveComment(Dictionary<string, string> Params)
		{
			FeedbackData retVal = null;
			TopicController.RemoveComment(Params, out retVal);
			return retVal;
		}
		[WebMethod]
		public FeedbackData SelectComments(Dictionary<string, string> Params)
		{
			FeedbackData retVal = null;
			TopicController.SelectComments(Params, out retVal);
			return retVal;
		}
		#endregion
	}
}
